#include "Adetector.h"
void GetFinalState_detector_photon(CDraw &para, AnalyseClass &analyse, AObject &object, TClonesArray *branchPhoton, MyPlots *plots,std::vector<Photon*> &photon, bool &Jphoton){
	int loop1=0,loopm=0,num;
	float pt,y;

	para.debug.Message(4,27,"in the photon function");
	if (para.signal.NUM_photon==0){
		Jphoton=true;
		return;
	} 

	num = branchPhoton->GetEntries();
	para.debug.Message(4,27,"photon num", num);
	if(para.photon.SWITCH){
		AFill_Plot(para,plots->fPhotonnum,num);
	}

	for(loop1=0;loop1<num;loop1++){
		Photon *photon_ptr = (Photon*) branchPhoton->At(loop1);
		pt = photon_ptr->PT;
		y  = std::abs(photon_ptr->Eta);
		if( para.photon.JCUT_pt  [0] == true && ( pt     < para.photon.CUT_ptd  [0] || pt     > para.photon.CUT_ptu  [0] )){para.debug.Message(5,27,"false: photon pt cut",pt);continue;}//endif
		if( para.photon.JCUT_eta [0] == true && ( y      < para.photon.CUT_etad [0] || y      > para.photon.CUT_etau [0] )){para.debug.Message(5,27,"false: photon etacut", y);continue;}//endif
		photon.push_back(photon_ptr);
		loopm++;
	}//endfor jet_Cindex

	if(para.photon.SWITCH ){
		if(loopm>=1&&loopm>=para.signal.NUM_photon){
			for(loop1=1;loop1<para.photon.CUT_num;loop1++){
				para.debug.Message(5,27,"in the cut loop, loopnum", loop1);
				pt   = photon[loop1-1]->PT;
				y    = std::abs(photon[loop1-1]->Eta);
				if( para.photon.JCUT_pt  [loop1] == true && ( pt     < para.photon.CUT_ptd  [loop1] || pt     > para.photon.CUT_ptu  [loop1] )){
					para.debug.Message(5,27,"false: photon pt cut",loop1,pt);
					Jphoton=false;
					return;
				}//endif
				if( para.photon.JCUT_eta [loop1] == true && ( y      < para.photon.CUT_etad [loop1] || y      > para.photon.CUT_etau [loop1] )){
					para.debug.Message(5,27,"false: photon etacut",loop1, y);
					Jphoton=false;
					return;
				}//endif
			}
			for(loop1=0;loop1<loopm;loop1++){
				para.debug.Message(5,27,"in the fill loop, fill plot", loop1);
				if(loop1<para.signal.NUM_photon){
					AFill_Plot(para,plots->fPhotonPT[loop1],photon[loop1]->PT);
					AFill_Plot(para,plots->fPhotonY[loop1] ,photon[loop1]->Eta);
				} 
			}
			para.debug.Message(4,27,"finish loop");
			Jphoton=true;
			return;
		}
		else{
			Jphoton=false;
			return;
		}
	}
	para.debug.Message(4,27,"finish photon detector");

	for(int i=0;i<photon.size();i++){
		object.Lphoton.push_back(photon[i]->P4());
	}
	std::sort(object.Lphoton.begin(),object.Lphoton.end(),TLV_compare_Pt);
	if(Jphoton){
		analyse.counter.getCounter("basic_photon");
	}
	return;
}




